package jp.co.hcs.attendancemanagement.data.dao.impl;

import java.sql.SQLException;
import java.util.List;

import jp.co.hcs.attendancemanagement.data.dao.HolidayDAO;
import jp.co.hcs.attendancemanagement.data.entity.Holiday;
import jp.co.hcs.attendancemanagement.data.entity.WorkingTimeActual;
import jp.co.hcs.attendancemanagement.data.entity.ex.HolidayExample;
import jp.co.hcs.attendancemanagement.data.entity.ex.HolidayExample.Criteria;

public class HolidayDAOImpl extends BaseDAOImpl implements HolidayDAO {

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_holiday
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public HolidayDAOImpl() {
        super();
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_holiday
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int countHolidayByExample(HolidayExample example) throws SQLException {
        Integer count = (Integer)  sqlMapClient.queryForObject("tb5_holiday.ibatorgenerated_countByExample", example);
        return count;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_holiday
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int deleteHolidayByExample(HolidayExample example) throws SQLException {
        int rows = sqlMapClient.delete("tb5_holiday.ibatorgenerated_deleteByExample", example);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_holiday
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int deleteHolidayByPrimaryKey(String holidayDay, String holidayYearMonth) throws SQLException {
        Holiday key = new Holiday();
        key.setHolidayDay(holidayDay);
        key.setHolidayYearMonth(holidayYearMonth);
        int rows = sqlMapClient.delete("tb5_holiday.ibatorgenerated_deleteByPrimaryKey", key);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_holiday
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public void insertHoliday(Holiday record) throws SQLException {
        sqlMapClient.insert("tb5_holiday.ibatorgenerated_insert", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_holiday
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public void insertHolidaySelective(Holiday record) throws SQLException {
        sqlMapClient.insert("tb5_holiday.ibatorgenerated_insertSelective", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_holiday
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    @SuppressWarnings("unchecked")
    public List<Holiday> selectHolidayByExample(HolidayExample example) throws SQLException {
        List<Holiday> list = sqlMapClient.queryForList("tb5_holiday.ibatorgenerated_selectByExample", example);
        return list;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_holiday
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public Holiday selectHolidayByPrimaryKey(String holidayDay, String holidayYearMonth) throws SQLException {
        Holiday key = new Holiday();
        key.setHolidayDay(holidayDay);
        key.setHolidayYearMonth(holidayYearMonth);
        Holiday record = (Holiday) sqlMapClient.queryForObject("tb5_holiday.ibatorgenerated_selectByPrimaryKey", key);
        return record;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_holiday
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int updateHolidayByExampleSelective(Holiday record, HolidayExample example) throws SQLException {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = sqlMapClient.update("tb5_holiday.ibatorgenerated_updateByExampleSelective", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_holiday
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int updateHolidayByExample(Holiday record, HolidayExample example) throws SQLException {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = sqlMapClient.update("tb5_holiday.ibatorgenerated_updateByExample", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_holiday
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int updateHolidayByPrimaryKeySelective(Holiday record) throws SQLException {
        int rows = sqlMapClient.update("tb5_holiday.ibatorgenerated_updateByPrimaryKeySelective", record);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_holiday
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int updateHolidayByPrimaryKey(Holiday record) throws SQLException {
        int rows = sqlMapClient.update("tb5_holiday.ibatorgenerated_updateByPrimaryKey", record);
        return rows;
    }

    /**
     * This class was generated by Apache iBATIS ibator.
     * This class corresponds to the database table tb5_holiday
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    private static class UpdateByExampleParms extends HolidayExample {
        private Object record;

        public UpdateByExampleParms(Object record, HolidayExample example) {
            super(example);
            this.record = record;
        }

        public Object getRecord() {
            return record;
        }
    }
    
    public boolean checkHolidaybyDay(String yearMonth, String day) throws SQLException
    {
    	boolean isHoliday = false;
    	HolidayExample example = new HolidayExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andHolidayYearMonthEqualTo(yearMonth);
    	criteria.andHolidayDayEqualTo(day);
    	
    	List<Holiday> holidayList = selectHolidayByExample(example);
    	if(holidayList.size() > 0)
    	{
    		isHoliday = true;
    	}
    	return isHoliday;
    }
}